package com.lh.rabbitmq.topic;

import com.lh.rabbitmq.utils.RabbitMQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * 主题模式生产者
 */
public class Product {
    public static void main(String[] args) {
        try {
            Connection connection = RabbitMQUtils.getConnection();
            Channel channel = connection.createChannel();
            String exchangeName = "topic_exchange";
            // 创建交换机
            channel.exchangeDeclare(exchangeName, "topic");
            // 绑定队列
            channel.queueBind("queue1", exchangeName, "com.#");
            channel.queueBind("queue2", exchangeName, "*.test");
            channel.queueBind("queue3", exchangeName, "#.other.*");
            // 发送消息
            channel.basicPublish(exchangeName, "com", null, new String("是幸运观众").getBytes());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
